package org.theSeed.base.pojo.vo;

import lombok.Getter;
import lombok.Setter;
import org.theSeed.base.pojo.sysEnum.SysCode;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * 通用返回结果
 * @param <T>
 */
@Getter
@Setter
public class R <T> implements Serializable {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 错误消息列表
     */
    private List<String> msgList;

    /**
     * 结果
     */
    private T data;

    public R() {
    }

    public R(Integer code, T data,List<String> msgList) {
        this.code = code;
        this.msgList = msgList;
        this.data = data;
    }

    //成功
    public static <T> R<T> success(){
        return new R<>(SysCode.SUCCESS.getCode(),null,null);
    }

    //成功
    public static <T> R<T> success(T data){
        return new R<>(SysCode.SUCCESS.getCode(),data,null);
    }

    //失败
    public static R fail(SysCode sysCode,String msg){
        return new R<>(sysCode.getCode(),null, Arrays.asList(msg));
    }

    //失败
    public static R fail(SysCode sysCode,String... msg){
        return new R<>(sysCode.getCode(),null, Arrays.asList(msg));
    }

    //自定义失败
    public static R fail(Integer code,String msg){
        return new R<>(code,null, Arrays.asList(msg));
    }

    //自定义失败
    public static R fail(Integer code,String... msg){
        return new R<>(code,null, Arrays.asList(msg));
    }
}
